package com.espirit.builder.biz;

import com.espirit.common.RelatedFile;
import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.manager.workflow.WFInstance;
import com.espirit.eap.pagelayout.FlatSection;
import com.espirit.eap.pagelayout.FunctionButton;
import com.espirit.eap.pagelayout.GridSection;
import com.espirit.eap.pagelayout.Model;

//@Component
public class FormBuilderSupport extends ModelBuilderSupport{

	protected static String ENTITY_STATUS = "entityStatus";
	protected static String CREATED = "created";
	protected static String CREATED_ON = "createdOn";
	protected static String REMARK = "remark";
	protected static final String EMPLOYEE = "employee";
	protected static final String DEPARTMENT = "department";
	protected static final String DEPTIDS = "deptIds";
	protected static final String PROOF_NBR = "proofNbr";
	protected static final String RELATED_FILES ="relatedFiles";
	
	FunctionButton goNext = null;
    
	
	@Override
	public boolean init() {
		return true;
	}
	
	@Override
	protected void setDefaultLayoutButtons() {
		super.setDefaultLayoutButtons();
		addButton(goNext);
	}
	
	protected boolean addRelatedFiles(){
		return false;
	}
	

	@Override
	public void buildFields() {
		goNext = createFunctionButton("_goNext", "Refer", "提交",this.clazz,"_goNext",false,null,null);
		
		addModelField(PROOF_NBR, "Number", "单号");
		addModelField(EMPLOYEE, "Employee", "职员");
		addModelField(DEPARTMENT, "Department", "部门");
		addModelField(DEPTIDS, "Department", "部门");
		
		addModelField(ENTITY_STATUS,"Status","状态");
		addModelField(CREATED,"Created","创建");
		addModelField(CREATED_ON,"Created On","创建时间");
		addModelField(REMARK,"Remark","备注");
	}
	
	@Override
	protected void afterBuilderLayout() {
		Model instance = getModel(WFInstance.class.getName());
		bindButtonToLayout(goNext, instance.getDefaultDetailLayout());
		
		if (addRelatedFiles()){
			FlatSection relatedFilesInfo = getDefaultDetailLayout().createFlatSection();
			GridSection gs = elementService.createSectionElement(relatedFilesInfo, getModelField(RELATED_FILES), getModel(RelatedFile.class).getDefaultListLayout().getMainGridSection());
			gs.setReadOnly(false);
			gs.setTagName("datagrid");
		}
		
		super.afterBuilderLayout();
	}
	
	
}
